﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using PiscoSourDominio;
using PiscoSourSOAPRestServices.Persistencia;
using Dapper;

namespace PiscoSourRESTServices.Persistencia
{
    public class OrdenDAO
    {
        public Orden ObtenerOrden(string codigo)
        {
            using (var sqlConnection = ConnectionFactory.GetConnection())
            {
                sqlConnection.Open();
                const string sqlQuery = "select * from prs_orden where intorden=@intorden";
                var orden = sqlConnection.Query<Orden>(sqlQuery, new { intorden = codigo }).SingleOrDefault<Orden>();

                sqlConnection.Close();

                return orden;
            }
        }

        public IEnumerable<Orden> ListarOrdenes()
        {
            using (var sqlConnection = ConnectionFactory.GetConnection())
            {
                sqlConnection.Open();
                var sqlQuery = string.Format(@"Select * from prs_orden");
                var result = sqlConnection.Query<Orden>(sqlQuery);
                sqlConnection.Close();
                return result;
            }
        }
    }
}